#!/bin/sh
#
# Use this script to regenerate the Protocol Buffer and gRPC files
# needed to build the example.
#
# Note that it requires updated protoc, protoc-gen-swift, and
# protoc-gen-grpc-swift binaries and assumes that protoc-gen-swift
# is installed in $HOME/local/bin.

if [ ! -d "googleapis" ]; then
  curl -L -O https://github.com/googleapis/googleapis/archive/master.zip
  unzip master.zip
  rm -f master.zip
  mv googleapis-master googleapis
fi

protoc \
	google/cloud/language/v1/language_service.proto \
	google/api/annotations.proto \
	google/api/http.proto \
	google/protobuf/descriptor.proto \
	-Igoogleapis \
	-I../common/include \
	--swift_out=googleapis \
	--grpc-swift_out=googleapis

# Move Swift files to the Sources directory. descriptor.pb.swift is provided
# with SwiftProtobuf (from 1.7.0).
find googleapis \
  -name "*.swift" \
  ! -name "descriptor.pb.swift" \
  -exec mv {} Sources \;
